﻿package com.truckdispatching;

import java.lang.Thread.UncaughtExceptionHandler;

import android.app.Application;
import android.content.Intent;

import com.truckdispatching.map.BaiduMapManager;
import com.umeng.analytics.MobclickAgent;

public class MyApplication extends Application {

	private static MyApplication mMyApplication = null;

	public static MyApplication getInstance() {
		return mMyApplication;
	}

	@Override
	public void onCreate() {
		MobclickAgent.onError(this);
		BaiduMapManager.getInstance().initBaiduMapManagerWithContext(this);
		mMyApplication = this;
		startPushService();
		Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

			@Override
			public void uncaughtException(Thread thread, Throwable ex) {
				ex.printStackTrace();
				onTerminate();
			}
		});
		super.onCreate();
	}

	private void startPushService() {
		Intent intent = new Intent();
		intent.setAction("com.truckdispatching.push_start");
		sendBroadcast(intent);
	}

	@Override
	public void onTerminate() {
		BaiduMapManager.getInstance().destroy();
		android.os.Process.killProcess(android.os.Process.myPid());
		super.onTerminate();
	}
}
